package com.lj.dict.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.common_web.annotation.ResponseResultVo;
import com.lj.dict.param.DictItemPageParam;
import com.lj.dict.param.DictItemSaveParam;
import com.lj.dict.param.DictItemUpdateParam;
import com.lj.dict.result.DictItemInfoResult;
import com.lj.dict.result.DictItemPageResult;
import com.lj.dict.service.DictItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典项表 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2025-01-10 11:16:54
 */
@RestController
@RequestMapping("/dict/dict_item")
@ResponseResultVo
@Tag(name = "字典项表 管理")
public class DictItemController {

    @Resource
    private DictItemService dictItemService;

    @GetMapping("/page")
    @SaCheckPermission("dict:dict_item:list")
    @Operation(summary = "字典项表 分页查询")
    public IPage<DictItemPageResult> page(@ParameterObject DictItemPageParam param) {
        return dictItemService.page(param);
    }

    @GetMapping("/info/{id}")
    @SaCheckPermission("dict:dict_item:info")
    @Operation(summary = "字典项表 信息")
    public DictItemInfoResult info(@PathVariable("id") @Parameter(name = "id", description = "字典项表 id") Long id) {
        if (id == null) {
            return null;
        }
        return dictItemService.info(id);
    }

    @PostMapping("/save")
    @SaCheckPermission("dict:dict_item:save")
    @Operation(summary = "字典项表 新增")
    public void save(@RequestBody @Validated DictItemSaveParam param) {
        dictItemService.save(param);
    }

    @PostMapping("/update")
    @SaCheckPermission("dict:dict_item:update")
    @Operation(summary = "字典项表 更新")
    public void update(@RequestBody @Validated DictItemUpdateParam param) {
        dictItemService.update(param);
    }

    @PostMapping("/delete")
    @SaCheckPermission("dict:dict_item:delete")
    @Operation(summary = "字典项表 删除")
    public void delete(@RequestBody List<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return;
        }
        dictItemService.removeByIds(ids);
    }
}

